#pragma once

#include "../Core/Transform.h"
#include "../Core/Ray.h"
#include "../Sdf/Sdf.h"
#include "../Render/Material.h"

namespace krt {

	struct KRT_API Intersection {
		glm::vec3 hitPoint;
		glm::vec3 normal;
		glm::vec2 uv;
		Ref<Material> material;
		Ref<ISdfBase> sdf;
		//bool isInRange; ?
	};

	class KRT_API Primitive {
	public:
		Primitive(Ref<Material> material)
			: m_Material(material)
		{}

		virtual bool Intersect(const Ray& r, Intersection& rec) const = 0;

	protected:
		Ref<Material> m_Material;

	};

	class KRT_API GeometryPrimitive : public Primitive {
	public:
		GeometryPrimitive(Ref<Material> material, Ref<ISdfBase> sdf)
			: Primitive(material), m_Sdf(sdf)
		{}

		virtual bool Intersect(const Ray& r, Intersection& rec) const override {
			SdfRecordType sdfRecT;
			float thit, epsilon;
			if (m_Sdf->Intersect(r, thit, epsilon, rec, sdfRecT)) {
				rec.material = m_Material;
				r.maxt = thit;
				return true;
			}
			return false;
		}

	protected:
		Ref<ISdfBase> m_Sdf;

	};

}